///*
// * The MIT License (MIT)
// *
// * Copyright (c) 2014-2016 abel533@gmail.com
// *
// * Permission is hereby granted, free of charge, to any person obtaining a copy
// * of this software and associated documentation files (the "Software"), to deal
// * in the Software without restriction, including without limitation the rights
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// * copies of the Software, and to permit persons to whom the Software is
// * furnished to do so, subject to the following conditions:
// *
// * The above copyright notice and this permission notice shall be included in
// * all copies or substantial portions of the Software.
// *
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// * THE SOFTWARE.
// */
//
//package com.wondream.myframework.app.config.mysql;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import com.github.pagehelper.PageHelper;
//import com.wondream.myframework.app.config.mysql.mutil.DynamicDataSource;
//import net.sf.log4jdbc.Log4jdbcProxyDataSource;
//import org.apache.ibatis.plugin.Interceptor;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.ClassPathResource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.sql.DataSource;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Properties;
//
///**
// * MyBatis基础配置
// *
// * @author liuzh
// * @since 2015-12-19 10:11
// */
//@Configuration
//@EnableTransactionManagement
//public class MyBatisConfig {
//
//    @Bean(name = "master")
//    @ConfigurationProperties(prefix = "master.datasource")
//    public DataSource masterDataSource() {
//        return new DruidDataSource();
//    }
//
//    @Bean(name = "quartzDataSource")
//    @ConfigurationProperties(prefix = "quartz.datasource")
//    public DataSource QuartzDataSource() {
//        return new DruidDataSource();
//    }
//
//    @Bean(name = "dataSource")
//    @Primary
//    public DynamicDataSource dataSource(@Qualifier("master") DataSource master, @Qualifier("quartzDataSource") DataSource quartzDataSource) {
//        DynamicDataSource dynamicDataSource = new DynamicDataSource();
//        dynamicDataSource.setDefaultTargetDataSource(master);
//
//        Map<Object, Object> targetDataSources = new HashMap<>();
//        targetDataSources.put("master", master);
//        targetDataSources.put("quartzDataSource", quartzDataSource);
//        dynamicDataSource.setTargetDataSources(targetDataSources);
//        dynamicDataSource.afterPropertiesSet();
//
//        return dynamicDataSource;
//    }
//
//    @Bean(name = "sqlSessionFactory")
//    @Autowired
//    public SqlSessionFactory sqlSessionFactoryBean(@Qualifier("dataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
//        sqlSessionFactory.setDataSource(getLog4jdbcProxyDataSource(dataSource));
//        sqlSessionFactory.setTypeAliasesPackage("com.zzqfsy.service.core.domain");
//        sqlSessionFactory.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
//        sqlSessionFactory.setFailFast(true);
//
//        //分页插件
//        PageHelper pageHelper = new PageHelper();
//        Properties properties = new Properties();
//        properties.setProperty("reasonable", "true");
//        properties.setProperty("supportMethodsArguments", "true");
//        properties.setProperty("returnPageInfo", "check");
//        properties.setProperty("params", "count=countSql");
//        pageHelper.setProperties(properties);
//        sqlSessionFactory.setPlugins(new Interceptor[]{pageHelper});
//
//        //添加XML目录
//        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
//        sqlSessionFactory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
//        return sqlSessionFactory.getObject();
//    }
//
//    public Log4jdbcProxyDataSource getLog4jdbcProxyDataSource(DataSource dataSource) {
//        return new Log4jdbcProxyDataSource(dataSource);
//    }
//
//    @Bean
//    public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//
//    @Bean
//    @Autowired
//    public DataSourceTransactionManager transactionManager(@Qualifier("dataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(getLog4jdbcProxyDataSource(dataSource));
//    }
//}
